﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xModel;
using Yule8xWechat.Applib;

namespace Yule8xWechat.Test
{
    public partial class Subscribe : System.Web.UI.Page
    {
        class TesterUserInfo
        {
            public string level { get; set; }
            public string nickname { get; set; }
            public int user_id { get; set; }
            public string unionid { get; set; }
            public string openid_biz { get; set; }
            public int game_id_bozhong { get; set; }
            public int parent1_uid { get; set; }
            public int parent2_uid { get; set; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Request.QueryString["action"];
            if (!string.IsNullOrEmpty(action) && action == "onekey")
            {
                IList<TesterUserInfo> users = new List<TesterUserInfo>();
                users.Add(new TesterUserInfo() { level = "1级", nickname = "詹辉", user_id = 1000, unionid = "ogQPs1S_uyyovmOcreV-R86BWsFI", openid_biz = "ou7IyxPpAeLI0RWr7STkTudcqAPs", game_id_bozhong = 0, parent1_uid = 0, parent2_uid = 0 });
                users.Add(new TesterUserInfo() { level = "2级", nickname = "兔子哥哥", user_id = 1001, unionid = "ogQPs1Xkv43KcKJk9SEGTN0XwdkQ", openid_biz = "ou7IyxEhRDaL6JRpNYrnkPsOcSlw", game_id_bozhong = 0, parent1_uid = 1000, parent2_uid = 0 });
                users.Add(new TesterUserInfo() { level = "3级", nickname = "Li.Li.Li", user_id = 1002, unionid = "ogQPs1YerRbkU8hPTx5hnld18i1w", openid_biz = "ou7IyxFMCvAN8_FVnAJn6W3nT2r0", game_id_bozhong = 0, parent1_uid = 1001, parent2_uid = 1000 });
                users.Add(new TesterUserInfo() { level = "4级", nickname = "苏苏的苏", user_id = 1003, unionid = "ogQPs1c0RVmMfmBHZPYEIIC7r4qc", openid_biz = "ou7IyxNMteGQIQjHuRN5ehuNvGYY", game_id_bozhong = 0, parent1_uid = 1000, parent2_uid = 0 });
                users.Add(new TesterUserInfo() { level = "5级", nickname = "天澜", user_id = 1004, unionid = "ogQPs1X6bAtttToMgBcUxHNLlRzc", openid_biz = "ou7IyxIe-0-lU4uqV17aDI7EOW08", game_id_bozhong = 0, parent1_uid = 1003, parent2_uid = 1000 });
                users.Add(new TesterUserInfo() { level = "6级", nickname = "丘", user_id = 1005, unionid = "ogQPs1cMeidWbOF_--ecvYR6Kz-M", openid_biz = "ou7IyxEDJV_AqxsKTisdWJiBrzmQ", game_id_bozhong = 0, parent1_uid = 1004, parent2_uid = 1003 });

                string sqlstmt, returnMsg;
                int uid;
                int dailycardcount = AppConf.ReferralUserDailyMaxCardCount; // 配置参数中的用户每天推广领卡最大数量
                int eachcardcount = AppConf.ReferralUserEachCardCount; // 配置参数中的每推广一个用户可获得的房卡数量
                foreach (TesterUserInfo user in users)
                {
                    uid = UserModels.UserRegistByQrcode(user.openid_biz,0, user.parent1_uid, dailycardcount, eachcardcount, "bozhong", out returnMsg);
                    Response.Write(string.Format("<br />用户注册结果：uid={0}, message={1}", uid, returnMsg));
                }
                Response.Redirect("UpdateUserInfo.aspx?action=onekey");
            }
        }

        protected void btn_submit_Click(object sender, EventArgs e)
        {
            string parent1_uid = tb_parent1_uid.Text.Trim();
            string openid = tb_openid.Text.Trim();
            int uid;
            string returnMsg;
            try
            {
                if (parent1_uid.Length > 0)
                {
                    int dailycardcount = AppConf.ReferralUserDailyMaxCardCount; // 配置参数中的用户每天推广领卡最大数量
                    int eachcardcount = AppConf.ReferralUserEachCardCount; // 配置参数中的每推广一个用户可获得的房卡数量
                    uid = UserModels.UserRegistByQrcode(openid, 0, int.Parse(parent1_uid), dailycardcount, eachcardcount, "bozhong", out returnMsg);
                }
                else
                {
                    uid = UserModels.UserRegistWithoutQrcode(openid, 0, out returnMsg);
                }
                Response.Write(string.Format("用户注册结果：uid={0}, message={1}", uid, returnMsg));

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
    }
}